#include <vector>
#include <iostream>
#include <numeric>
#include <algorithm>
using namespace std;

int min_long(vector<vector<int>> &m, int u, vector<int> &path)
{
        if(u == m.size()-1){
                return 0;
        }
        int n = m.size();
        int ans = INT32_MAX, sel = -1;
        path.push_back(u); // Add the current node to the path
        for(int i = 0; i < n; i++){
                if(m[u][i]){
                        auto min = min_long(m, i, path);
                        if(min + m[u][i] < ans){
                                ans = min + m[u][i];
                                sel = i;
                        }
                }
        }
        path[u] = sel;

        return ans;
}

int min_long1(vector<vector<int>> &m, int u, vector<int> &path)
{
        if(u == m.size()-1){
                return 0;
        }
        int n = m.size();
        int ans = INT32_MAX, sel = -1;
        //path.push_back(u);
        for(int i = 0; i < n; i++){
                if(m[u][i]){
                        path.push_back(i);
                        auto min = min_long(m, i, path);
                        
                        if(min + m[u][i] < ans){
                                ans = min + m[u][i];
                                sel = i;
                        }else{
                                path.pop_back();
                        }
                }
        }
        return ans;
}

int main()
{
        int n = 0;
        cin >> n;
        vector<vector<int>> matrix(n, vector<int>(n));
        for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                        cin>>matrix[i][j];
                }
        }
        vector<int> path;
        int ans = min_long1(matrix, 0, path);
        cout<<"minlong="<<ans<<endl;
        
        for(auto v : path){
                cout<<v<<"";
        }
        return 0;
}